package com.hjm.project.posRequestdata.posRequestdata.controller;

import java.util.List;

import com.hjm.common.utils.Utils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.posRequestdata.posRequestdata.domain.PosRequestdata;
import com.hjm.project.posRequestdata.posRequestdata.service.IPosRequestdataService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 终端请求Controller
 * 
 * @author LOVE
 * @date 2020-11-27
 */
@Controller
@RequestMapping("/posRequestdata/posRequestdata")
public class PosRequestdataController extends BaseController
{
    private String prefix = "posRequestdata/posRequestdata";

    @Autowired
    private IPosRequestdataService posRequestdataService;

    @RequiresPermissions("posRequestdata:posRequestdata:view")
    @GetMapping()
    public String posRequestdata()
    {
        return prefix + "/posRequestdata";
    }

    /**
     * 查询终端请求列表
     */
    @RequiresPermissions("posRequestdata:posRequestdata:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PosRequestdata posRequestdata)throws Exception
    {
        startPage();
        List<PosRequestdata> list = posRequestdataService.selectPosRequestdataList(posRequestdata);
        for(int i=0;i<list.size();i++){
            list.get(i).setPan(Utils.dealCard(list.get(i).getPan()));
        }
        return getDataTable(list);
    }

    /**
     * 导出终端请求列表
     */
    @RequiresPermissions("posRequestdata:posRequestdata:export")
    @Log(title = "终端请求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PosRequestdata posRequestdata)
    {
        List<PosRequestdata> list = posRequestdataService.selectPosRequestdataList(posRequestdata);
        ExcelUtil<PosRequestdata> util = new ExcelUtil<PosRequestdata>(PosRequestdata.class);
        return util.exportExcel(list, "posRequestdata");
    }

    /**
     * 新增终端请求
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存终端请求
     */
    @RequiresPermissions("posRequestdata:posRequestdata:add")
    @Log(title = "终端请求", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PosRequestdata posRequestdata)
    {
        return toAjax(posRequestdataService.insertPosRequestdata(posRequestdata));
    }

    /**
     * 修改终端请求
     */
    @GetMapping("/edit/{serial}")
    public String edit(@PathVariable("serial") Long serial, ModelMap mmap)
    {
        PosRequestdata posRequestdata = posRequestdataService.selectPosRequestdataById(serial);
        mmap.put("posRequestdata", posRequestdata);
        return prefix + "/edit";
    }

    /**
     * 修改保存终端请求
     */
    @RequiresPermissions("posRequestdata:posRequestdata:edit")
    @Log(title = "终端请求", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PosRequestdata posRequestdata)
    {
        return toAjax(posRequestdataService.updatePosRequestdata(posRequestdata));
    }

    /**
     * 删除终端请求
     */
    @RequiresPermissions("posRequestdata:posRequestdata:remove")
    @Log(title = "终端请求", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(posRequestdataService.deletePosRequestdataByIds(ids));
    }
}
